#include "stdafx.h"
#include "SkiaPaint.h"

MyColor::MyColor(){
    m_lastStyle = -1;
}
MyColor::~MyColor(){
    
}

static String m_systemFont;

void MyColor::setSystemFont(String value){
    m_systemFont = value;
}

String MyColor::getSystemFont(){
    if ((int)m_systemFont.length() == 0)
    {
        m_systemFont = L"SimSun";
    }
    return m_systemFont;
}

static int m_style = 0;

int MyColor::getStyle(){
    return m_style;
}
void MyColor::setStyle(int value){
    m_style = value;
}

void MyColor::createColors(){ 
	m_userColors.clear();
	if (m_style == 1)
    {
        m_userColors.put(FCColor_Back, FCColor::rgb(255, 255, 255)); //1
        m_userColors.put(FCColor_Border, FCColor::rgb(200, 200, 200)); //1
        m_userColors.put(FCColor_Text, FCColor::rgb(0, 0, 0)); //1
        m_userColors.put(FCColor_DisabledBack, FCColor::rgba(0, 0, 0, 25)); //1
        m_userColors.put(FCColor_DisabledText, 3289650);
        m_userColors.put(FCColor_Hovered, FCColor::rgba(43, 138, 195, 150));
        m_userColors.put(FCColor_Pushed, FCColor::rgba(43, 138, 195, 100));
    }else{
        m_userColors.put(FCColor_Back, FCColor::rgb(19, 21, 26));
        m_userColors.put(FCColor_Border, FCColor::rgb(50, 50, 50));
        m_userColors.put(FCColor_Text, FCColor::rgb(255, 255, 255));
        m_userColors.put(FCColor_DisabledBack, FCColor::rgba(255, 255, 255, 25));
        m_userColors.put(FCColor_DisabledText, 3289650);
        m_userColors.put(FCColor_Hovered, FCColor::rgba(43, 138, 195, 150));
        m_userColors.put(FCColor_Pushed, FCColor::rgba(43, 138, 195, 100));
    }
}

Long MyColor::getUserColor(Long color){
    if (m_lastStyle != m_style)
    {
        m_lastStyle = m_style;
       createColors();
    }
    if (m_userColors.containsKey(color))
    {
       color = m_userColors.get(color);
    }
    return color;
}

void SkiaPaint::affectScaleFactor(SkRect * skRect){
	if (m_scaleFactorX != 1 || m_scaleFactorY != 1)
	{
		SkRect newSkRect = { (int)(skRect->left() * m_scaleFactorX),
			(int)(skRect->top() * m_scaleFactorY), (int)(skRect->right() * m_scaleFactorX),
			(int)(skRect->bottom() * m_scaleFactorY) };
		*skRect = newSkRect;
	}
}

SkColor SkiaPaint::getSkColor(Long dwPenColor) {
	Long c = dwPenColor;
	if (dwPenColor < FCColor_None)
	{
		dwPenColor = m_myColor->getUserColor(dwPenColor);
	}
	int a = 255;
	if (dwPenColor < 0)
	{
		dwPenColor = abs(dwPenColor);
		a = (int)(dwPenColor - dwPenColor / 1000 * 1000);
		dwPenColor /= 1000;
	}
	if (m_opacity < 1)
	{
		a = (int)(a * m_opacity);
	}
	int r = (int)(dwPenColor & 0xff);
	int g = (int)((dwPenColor >> 8) & 0xff);
	int b = (int)((dwPenColor >> 0x10) & 0xff);
	return SkColorSetARGB(a, r, g, b);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SkiaPaint::SkiaPaint(){
	m_bitmap = 0;
	m_canvas = 0;
	m_exportPath = L"";
	m_imageSize.cx = 0;
	m_imageSize.cy = 0;
	m_isClip = false;
	m_isPathStart = false;
	m_offsetX = 0;
	m_offsetY = 0;
	m_opacity = 1;
	m_path = 0;
	m_pRect.left = 0;
	m_pRect.top = 0;
	m_pRect.right = 0;
	m_pRect.bottom = 0;
	m_resourcePath = L"";
	m_rotateAngle = 0;
	m_render = 0;
	m_scaleFactorX = 0;
	m_scaleFactorY = 0;
	m_surface = 0;
	m_wRect.left = 0;
	m_wRect.top = 0;
	m_wRect.right = 0;
	m_wRect.bottom = 0;
	m_myColor = new MyColor;
}

SkiaPaint::~SkiaPaint(){
	clearCaches();
	if(m_bitmap){
		delete m_bitmap;
		m_bitmap = 0;
	}
	if(m_surface){
		SDL_FreeSurface(m_surface);
		m_surface = 0;
	}
	m_canvas = 0;
	m_render = 0;
	if(m_myColor){
		delete m_myColor;
		m_myColor = 0;
	}
}

void SkiaPaint::addArc(const FCRect& rect, float startAngle, float sweepAngle){
	SkRect skRect = { rect.left + m_offsetX, rect.top + m_offsetY, rect.right + m_offsetX, rect.bottom + m_offsetY };
	affectScaleFactor(&skRect);
	m_path->addArc(skRect, startAngle, sweepAngle);
}

void SkiaPaint::addBezier(FCPoint *apt, int cpt){
}

void SkiaPaint::addCurve(FCPoint *apt, int cpt){
}

void SkiaPaint::addEllipse(const FCRect& rect){
	SkRect skRect = { rect.left + m_offsetX, rect.top + m_offsetY, rect.right + m_offsetX, rect.bottom + m_offsetY };
	affectScaleFactor(&skRect);
	m_path->addOval(skRect);
}

void SkiaPaint::addLine(int x1, int y1, int x2, int y2){
	int lx1 = x1 + m_offsetX;
	int ly1 = y1 + m_offsetY;
	int lx2 = x2 + m_offsetX;
	int ly2 = y2 + m_offsetY;
	if (m_scaleFactorX != 1 || m_scaleFactorY != 1)
	{
		lx1 = (int)(m_scaleFactorX * lx1);
		ly1 = (int)(m_scaleFactorY * ly1);
		lx2 = (int)(m_scaleFactorX * lx2);
		ly2 = (int)(m_scaleFactorY * ly2);
	}
	if (m_isPathStart)
	{
		m_isPathStart = false;
		m_path->moveTo(lx1, ly1);
	}
	m_path->lineTo(lx2, ly2);
}

void SkiaPaint::addRect(const FCRect& rect){
	SkRect skRect = { rect.left + m_offsetX, rect.top + m_offsetY, rect.right + m_offsetX, rect.bottom + m_offsetY };
	affectScaleFactor(&skRect);
	m_path->addRect(skRect);
}

void SkiaPaint::addPie(const FCRect& rect, float startAngle, float sweepAngle){

}

void SkiaPaint::addText(String strText, FCFont *font, const FCRect& rect, int width){
	
}

void SkiaPaint::beginExport(const String& exportPath, const FCRect& rect){
	m_exportPath = exportPath;
    m_opacity = 1;
    m_resourcePath = L"";
}

void SkiaPaint::beginPaint(int hDC, const FCRect& wRect, const FCRect& pRect){	
	m_pRect = pRect;
	m_wRect = wRect;
	int width = m_wRect.right - m_wRect.left;
	int height = m_wRect.bottom - m_wRect.top;
	if(width > m_imageSize.cx || height > m_imageSize.cy || !m_bitmap){
		if(m_bitmap){
			delete m_bitmap;
		}
		m_bitmap = new SkBitmap();
		m_bitmap->setInfo(SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kOpaque_SkAlphaType));
		m_bitmap->allocPixels();
		if(m_canvas){
			delete m_canvas;
		}
		m_canvas = new SkCanvas(*m_bitmap);
		if(m_surface){
			SDL_FreeSurface(m_surface);
		}
		m_surface = SDL_CreateRGBSurfaceFrom(m_bitmap->getPixels(), width, height, 32, width * 4, 0x00ff0000, 0x0000ff00,
        	0x000000ff, 0xff000000);
	}
	m_opacity = 1;
	m_resourcePath = L"";
	m_isClip = false;
	m_isPathStart = false;
}

void SkiaPaint::beginPath(){
	m_path = new SkPath();
	m_isPathStart = true;
}

void SkiaPaint::clearCaches(){

}

void SkiaPaint::clipPath(){
}

void SkiaPaint::closeFigure(){
	m_path->close();
}

void SkiaPaint::closePath(){
	if (m_path)
	{
		delete m_path;
		m_path = 0;
	}
	m_isPathStart = false;
}

void SkiaPaint::drawArc(Long dwPenColor, float width, int style, const FCRect& rect, float startAngle, float sweepAngle){
	if (dwPenColor == FCColor_None) return;
	SkRect skRect = { rect.left + m_offsetX, rect.top + m_offsetY, rect.right + m_offsetX, rect.bottom + m_offsetY };
	affectScaleFactor(&skRect);
	m_paint.setColor(getSkColor(dwPenColor));
	m_paint.setStyle(SkPaint::Style::kStroke_Style);
	float lineWidth = (float)(width * std::min(m_scaleFactorX, m_scaleFactorY));
	m_paint.setStrokeWidth(lineWidth);
	m_canvas->drawArc(skRect, startAngle, sweepAngle, true, m_paint);
}

void SkiaPaint::drawBezier(Long dwPenColor, float width, int style, FCPoint *apt, int cpt){

}

void SkiaPaint::drawCurve(Long dwPenColor, float width, int style, FCPoint *apt, int cpt){
	
}

void SkiaPaint::drawEllipse(Long dwPenColor, float width, int style, const FCRect& rect){
	if (dwPenColor == FCColor_None) return;
	SkRect skRect = { rect.left + m_offsetX, rect.top + m_offsetY, rect.right + m_offsetX, rect.bottom + m_offsetY };
	affectScaleFactor(&skRect);
	m_paint.setColor(getSkColor(dwPenColor));
	m_paint.setStyle(SkPaint::Style::kStroke_Style);
	float lineWidth = (float)(width * std::min(m_scaleFactorX, m_scaleFactorY));
	m_paint.setStrokeWidth(lineWidth);
	m_canvas->drawOval(skRect, m_paint);
}

void SkiaPaint::drawEllipse(Long dwPenColor, float width, int style, int left, int top, int right, int bottom){
	FCRect rect = {left, top, right, bottom};
    drawEllipse(dwPenColor, width, style, rect);
}

void SkiaPaint::drawImage(String imagePath, const FCRect& rect){
	
}

void SkiaPaint::drawLine(Long dwPenColor, float width, int style, const FCPoint& x, const FCPoint& y){
	drawLine(dwPenColor, width, style, x.x, x.y, y.x, y.y);
}

void SkiaPaint::drawLine(Long dwPenColor, float width, int style, int x1, int y1, int x2, int y2){
	if (dwPenColor == FCColor_None) return;
	m_paint.setColor(getSkColor(dwPenColor));
	m_paint.setStyle(SkPaint::Style::kStroke_Style);
	float lineWidth = (float)(width * std::min(m_scaleFactorX, m_scaleFactorY));
	m_paint.setStrokeWidth(lineWidth);
	int lx1 = x1 + m_offsetX;
	int ly1 = y1 + m_offsetY;
	int lx2 = x2 + m_offsetX;
	int ly2 = y2 + m_offsetY;
	if (m_scaleFactorX != 1 || m_scaleFactorY != 1)
	{
		lx1 = (int)(m_scaleFactorX * lx1);
		ly1 = (int)(m_scaleFactorY * ly1);
		lx2 = (int)(m_scaleFactorX * lx2);
		ly2 = (int)(m_scaleFactorY * ly2);
	}
	m_canvas->drawLine(lx1, ly1, lx2, ly2, m_paint);
}

void SkiaPaint::drawPath(Long dwPenColor, float width, int style){
	if (dwPenColor == FCColor_None) return;
	m_paint.setColor(getSkColor(dwPenColor));
	m_paint.setStyle(SkPaint::Style::kStroke_Style);
	float lineWidth = (float)(width * std::min(m_scaleFactorX, m_scaleFactorY));
	m_paint.setStrokeWidth(lineWidth);
	m_canvas->drawPath(*m_path, m_paint);
}

void SkiaPaint::drawPie(Long dwPenColor, float width, int style, const FCRect& rect, float startAngle, float sweepAngle){

}

void SkiaPaint::drawPolygon(Long dwPenColor, float width, int style, FCPoint *apt, int cpt){
	if (dwPenColor == FCColor_None) return;
	m_paint.setColor(getSkColor(dwPenColor));
	m_paint.setStyle(SkPaint::Style::kStroke_Style);
	float lineWidth = (float)(width * std::min(m_scaleFactorX, m_scaleFactorY));
	m_paint.setStrokeWidth(lineWidth);
	SkPath path;
	for (int i = 0; i < cpt; i++)
	{
		int x = apt[i].x + m_offsetX;
		int y = apt[i].y + m_offsetY;
		if (m_scaleFactorX != 1 || m_scaleFactorY != 1)
		{
			x = (int)(m_scaleFactorX * x);
			y = (int)(m_scaleFactorY * y);
		}
		if (i == 0)
		{
			path.moveTo(x, y);
		}
		else
		{
			path.lineTo(x, y);
		}
	}
	path.close();
	m_canvas->drawPath(path, m_paint);
}

void SkiaPaint::drawPolyline(Long dwPenColor, float width, int style, FCPoint *apt, int cpt){
	if (dwPenColor == FCColor_None) return;
	m_paint.setColor(getSkColor(dwPenColor));
	m_paint.setStyle(SkPaint::Style::kStroke_Style);
	float lineWidth = (float)(width * std::min(m_scaleFactorX, m_scaleFactorY));
	m_paint.setStrokeWidth(lineWidth);
	SkPath path;
	for (int i = 0; i < cpt; i++)
	{
		int x = apt[i].x + m_offsetX;
		int y = apt[i].y + m_offsetY;
		if (m_scaleFactorX != 1 || m_scaleFactorY != 1)
		{
			x = (int)(m_scaleFactorX * x);
			y = (int)(m_scaleFactorY * y);
		}
		if (i == 0)
		{
			path.moveTo(x, y);
		}
		else
		{
			path.lineTo(x, y);
		}
	}
	m_canvas->drawPath(path, m_paint);
}

void SkiaPaint::drawRect(Long dwPenColor, float width, int style, int left, int top, int right, int bottom){
	FCRect rect = {left, top, right, bottom};
    drawRect(dwPenColor, width, style, rect);
}

void SkiaPaint::drawRect(Long dwPenColor, float width, int style, const FCRect& rect){
	if (dwPenColor == FCColor_None) return;
	SkRect skRect = { rect.left + m_offsetX, rect.top + m_offsetY, rect.right + m_offsetX - 1, rect.bottom + m_offsetY - 1 };
	affectScaleFactor(&skRect);
	m_paint.setColor(getSkColor(dwPenColor));
	m_paint.setStyle(SkPaint::Style::kStroke_Style);
	float lineWidth = (float)(width * std::min(m_scaleFactorX, m_scaleFactorY));
	m_paint.setStrokeWidth(lineWidth);
	m_canvas->drawRect(skRect, m_paint);
}

void SkiaPaint::drawRoundRect(Long dwPenColor, float width, int style, const FCRect& rect, int cornerRadius){
	if (cornerRadius > 0) {
		if (dwPenColor == FCColor_None) return;
		SkRect skRect = { rect.left + m_offsetX, rect.top + m_offsetY, rect.right + m_offsetX - 1, rect.bottom + m_offsetY - 1 };
		affectScaleFactor(&skRect);
		m_paint.setColor(getSkColor(dwPenColor));
		m_paint.setStyle(SkPaint::Style::kStroke_Style);
		float lineWidth = (float)(width * std::min(m_scaleFactorX, m_scaleFactorY));
		m_paint.setStrokeWidth(lineWidth);
		m_canvas->drawRoundRect(skRect, cornerRadius, cornerRadius, m_paint);
	}
	else {
		drawRect(dwPenColor, width, style, rect);
	}
}

void SkiaPaint::drawText(String strText, Long dwPenColor, FCFont *font, const FCRect& rect, int width){
	if (dwPenColor == FCColor_None) return;
	String fontFamily = font->m_fontFamily;
	String newFont = L"";
	if (fontFamily == L"Default")
	{
		String sysFont = MyColor::getSystemFont();
		newFont = sysFont;
	}
	else
	{
		newFont = font->m_fontFamily;
	}
	m_paint.setColor(getSkColor(dwPenColor));
	m_paint.setStyle(SkPaint::Style::kFill_Style);
	const char* str = FCTran::StringTostring(strText).c_str();
	if (m_scaleFactorX != 1 || m_scaleFactorY != 1)
	{
		int strX = (int)(m_scaleFactorX * (rect.left + m_offsetX));
		int strY = (int)(m_scaleFactorY * (rect.top + m_offsetY));
		float fontSize = (float)(font->m_fontSize * (m_scaleFactorX + m_scaleFactorY) / 2);
		FCFont scaleFont(font->m_fontFamily, fontSize, font->m_bold, font->m_underline, font->m_italic);
		/*SkFont skFont;
		skFont.setSize(scaleFont.m_fontSize + 2);
		skFont.setTypeface(SkTypeface::MakeFromName(FCTran::StringTostring(newFont).c_str(), SkFontStyle::Normal()));
		SkFontMetrics fm;
		skFont.getMetrics(&fm);
		float baseLineY = ((int)((rect.bottom + m_offsetY) * m_scaleFactorY) + (int)((rect.top + m_offsetY) * m_scaleFactorY) - fm.fBottom - fm.fTop) / 2;
		m_canvas->drawSimpleText(str, strlen(str), SkTextEncoding::kUTF8, strX, baseLineY, skFont, m_paint);*/
	}
	else
	{
		/*SkFont skFont;
		skFont.setSize(font->m_fontSize + 2);
		skFont.setTypeface(SkTypeface::MakeFromName(FCTran::StringTostring(newFont).c_str(), SkFontStyle::Normal()));
		SkFontMetrics fm;
		skFont.getMetrics(&fm);
		float baseLineY = ((rect.bottom + m_offsetY) + (rect.top + m_offsetY) - fm.fBottom - fm.fTop) / 2;
		m_canvas->drawSimpleText(str, strlen(str), SkTextEncoding::kUTF8, rect.left + m_offsetX, baseLineY, skFont, m_paint);*/
	}
}

void SkiaPaint::drawTextWithPos(String strText, Long dwPenColor, FCFont *font, int x, int y){
	FCSize tSize = textSize(strText, font, -1);
	FCRect tRect = { x, y, x + tSize.cx, y + tSize.cy};
	drawText(strText, dwPenColor, font, tRect, -1);
}

void SkiaPaint::drawText(String strText, Long dwPenColor, FCFont *font, const FCRectF& rect, int width){
	FCRect lRect = { rect.left, rect.top, rect.right, rect.bottom };
	drawText(strText, dwPenColor, font, lRect, -1);
}

void SkiaPaint::drawTextAutoEllipsis(String strText, Long dwPenColor, FCFont *font, const FCRect& rect){
	drawText(strText, dwPenColor, font, rect, -1);
}

void SkiaPaint::endExport(){
    m_offsetX = 0;
    m_offsetY = 0;
    m_opacity = 1;
    m_resourcePath = L"";
}

void SkiaPaint::endPaint(){
	SDL_RenderClear(m_render);
    SDL_Texture *texture = SDL_CreateTextureFromSurface(m_render, m_surface);
	SDL_Rect rect = { 0, 0, m_surface->w, m_surface->h };
    SDL_RenderCopy(m_render, texture, NULL, &rect);
    SDL_RenderPresent(m_render);
    SDL_DestroyTexture(texture);
	m_offsetX = 0;
	m_offsetY = 0;
	m_opacity = 1;
	m_resourcePath = L"";
}

void SkiaPaint::excludeClipPath(){
}

void SkiaPaint::fillEllipse(Long dwPenColor, const FCRect& rect){
	if (dwPenColor == FCColor_None) return;
	SkRect skRect = { rect.left + m_offsetX, rect.top + m_offsetY, rect.right + m_offsetX, rect.bottom + m_offsetY };
	affectScaleFactor(&skRect);
	m_paint.setColor(getSkColor(dwPenColor));
	m_paint.setStyle(SkPaint::Style::kFill_Style);
	m_canvas->drawOval(skRect, m_paint);
}

void SkiaPaint::fillGradientEllipse(Long dwFirst, Long dwSecond, const FCRect& rect, int angle){
	fillEllipse(dwFirst, rect);
}

void SkiaPaint::fillGradientPath(Long dwFirst, Long dwSecond, const FCRect& rect, int angle){
	fillPath(dwFirst);
}

void SkiaPaint::fillGradientPolygon(Long dwFirst, Long dwSecond, FCPoint *apt, int cpt, int angle){
	fillPolygon(dwFirst, apt, cpt);
}

void SkiaPaint::fillGradientRect(Long dwFirst, Long dwSecond, const FCRect& rect, int cornerRadius, int angle){
	fillRect(dwFirst, rect);
}

void SkiaPaint::fillPath(Long dwPenColor){
	if (dwPenColor == FCColor_None) return;
	m_paint.setColor(getSkColor(dwPenColor));
	m_paint.setStyle(SkPaint::Style::kFill_Style);
	m_canvas->drawPath(*m_path, m_paint);
}

void SkiaPaint::fillPie(Long dwPenColor, const FCRect& rect, float startAngle, float sweepAngle){

}

void SkiaPaint::fillPolygon(Long dwPenColor, FCPoint *apt, int cpt){
	if (dwPenColor == FCColor_None) return;
	m_paint.setColor(getSkColor(dwPenColor));
	m_paint.setStyle(SkPaint::Style::kFill_Style);
	SkPath path;
	for (int i = 0; i < cpt; i++)
	{
		int x = apt[i].x + m_offsetX;
		int y = apt[i].y + m_offsetY;
		if (m_scaleFactorX != 1 || m_scaleFactorY != 1)
		{
			x = (int)(m_scaleFactorX * x);
			y = (int)(m_scaleFactorY * y);
		}
		if (i == 0)
		{
			path.moveTo(x, y);
		}
		else
		{
			path.lineTo(x, y);
		}
	}
	path.close();
	m_canvas->drawPath(path, m_paint);
}

void SkiaPaint::fillRect(Long dwPenColor, const FCRect& rect){
	fillRect(dwPenColor, rect.left, rect.top, rect.right, rect.bottom);
}

void SkiaPaint::fillRect(Long dwPenColor, int left, int top, int right, int bottom){
	if (dwPenColor == FCColor_None) return;
	SkRect skRect = { left + m_offsetX, top + m_offsetY, right + m_offsetX, bottom + m_offsetY };
	affectScaleFactor(&skRect);
	m_paint.setColor(getSkColor(dwPenColor));
	m_paint.setStyle(SkPaint::Style::kFill_Style);
	m_canvas->drawRect(skRect, m_paint);
}

void SkiaPaint::fillRoundRect(Long dwPenColor, const FCRect& rect, int cornerRadius){
	if (cornerRadius > 0) {
		if (dwPenColor == FCColor_None) return;
		SkRect skRect = { rect.left + m_offsetX, rect.top + m_offsetY, rect.right + m_offsetX, rect.bottom + m_offsetY };
		affectScaleFactor(&skRect);
		m_paint.setColor(getSkColor(dwPenColor));
		m_paint.setStyle(SkPaint::Style::kFill_Style);
		m_canvas->drawRoundRect(skRect, cornerRadius, cornerRadius, m_paint);
	}
	else {
		fillRect(dwPenColor, rect);
	}
}

Long SkiaPaint::getColor(Long dwPenColor){
	return m_myColor->getUserColor(dwPenColor);
}

Long SkiaPaint::getPaintColor(Long dwPenColor){
	return getColor(dwPenColor);
}

FCPoint SkiaPaint::getOffset(){
	FCPoint offset = {m_offsetX, m_offsetY};
	return offset;
}

void SkiaPaint::getScaleFactor(double *scaleFactorX, double *scaleFactorY){
	*scaleFactorX = m_scaleFactorX;
	*scaleFactorY = m_scaleFactorY;
}

FCPoint SkiaPaint::rotate(const FCPoint& op, const FCPoint& mp, int angle){
    float PI = 3.14159265f;
	FCPoint pt = {0};
    pt.x = (int)((mp.x - op.x) * cos(angle * PI / 180) - (mp.y - op.y) * sin(angle * PI / 180) + op.x);
    pt.y = (int)((mp.x - op.x) * sin(angle * PI / 180) + (mp.y - op.y) * cos(angle * PI / 180) + op.y);
    return pt;
}

void SkiaPaint::setClip(const FCRect& rect){
	if (m_isClip)
	{
		m_canvas->restore();
	}
	SkRect skRect = { rect.left + m_offsetX, rect.top + m_offsetY, rect.right + m_offsetX, rect.bottom + m_offsetY };
	affectScaleFactor(&skRect);
	m_canvas->save();
	m_canvas->clipRect(skRect);
	m_isClip = true;
}

void SkiaPaint::setLineCap(int startLineCap, int endLineCap){
    
}

void SkiaPaint::setOffset(const FCPoint& offset){
	m_offsetX = offset.x;
	m_offsetY = offset.y;
}

void SkiaPaint::setOpacity(float opacity){
	if(m_opacity != opacity){
		m_opacity = opacity;
	}
}

void SkiaPaint::setResourcePath(const String& resourcePath){
	m_resourcePath = resourcePath;
}

void SkiaPaint::setRotateAngle(int rotateAngle){
	m_rotateAngle = rotateAngle;
}

void SkiaPaint::setScaleFactor(double scaleFactorX, double scaleFactorY){
	m_scaleFactorX = scaleFactorX;
	m_scaleFactorY = scaleFactorY;
}

bool SkiaPaint::supportTransparent(){
	return true;
}

FCSize SkiaPaint::textSize(String strText, FCFont *font, int width){
	FCSizeF fSize = textSizeF(strText, font, width);
	FCSize size = { fSize.cx, fSize.cy };
	return size;
}

FCSizeF SkiaPaint::textSizeF(String strText, FCFont *font, int width){
	String fontFamily = font->m_fontFamily;
	String newFont = L"";
	if (fontFamily == L"Default")
	{
		newFont = MyColor::getSystemFont();
	}
	else
	{
		newFont = font->m_fontFamily;
	}
	float rate = (float)((m_scaleFactorX + m_scaleFactorY) / 2);
	/*SkFont skFont;
	skFont.setSize(font->m_fontSize * rate + 2);
	skFont.setTypeface(SkTypeface::MakeFromName(FCTran::StringTostring(newFont).c_str(), SkFontStyle::Normal()));
	SkFontMetrics fm;
	skFont.getMetrics(&fm);
	const char* str = FCTran::StringTostring(strText).c_str();
	FCSizeF sizeF = { skFont.measureText(str, strlen(str) / rate, SkTextEncoding::kUTF8), (fm.fDescent - fm.fAscent) / rate };
	return sizeF;*/
	FCSizeF sizeF = {100, 20};
	return sizeF;

}
